package com.zzy.chapter3.deprecated.state;

import com.zzy.chapter3.utils.RedisCommonProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DeprecatedCreateOrder extends DeprecatedAbstractOrderState {

    @Autowired
    private RedisCommonProcessor redisCommonProcessor;

    @Autowired
    private DeprecatedAbstractOrderState orderState;

    @Override
    protected DeprecatedOrder createOrder(String orderId, String productId) {
        // 1. 创建订单
        DeprecatedOrder order = DeprecatedOrder.builder()
                .orderId(orderId)
                .productId(productId)
                .state(ORDER_WAIT_PAY)
                .build();
        // 2. 存入redis-15分钟
        redisCommonProcessor.set(orderId, order, 900);
        // 3. 发送订单创建的event
        orderState.payOrder(orderId);
        // 4. 设置上下文状态为待支付

        return order;
    }
}
